package app.dao;

import java.util.List;
import org.hibernate.LockMode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import app.model.Tbluserinrole;

/**
 * A data access object (DAO) providing persistence and search support for
 * Tbluserinrole entities. Transaction control of the save(), update() and
 * delete() operations can directly support Spring container-managed
 * transactions or they can be augmented to handle user-managed Spring
 * transactions. Each of these methods provides additional information for how
 * to configure it for the desired type of transaction control.
 * 
 * @see app.model.Tbluserinrole
 * @author MyEclipse Persistence Tools
 */

public class TbluserinroleDAO extends HibernateDaoSupport implements IUserInRole {
	private static final Logger log = LoggerFactory
			.getLogger(TbluserinroleDAO.class);
	protected void initDao() {
		// do nothing
	}

	/* (non-Javadoc)
	 * @see app.dao.IUserInRole#save(app.model.Tbluserinrole)
	 */
	public void save(Tbluserinrole transientInstance) {
		log.debug("saving Tbluserinrole instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see app.dao.IUserInRole#delete(app.model.Tbluserinrole)
	 */
	public void delete(Tbluserinrole persistentInstance) {
		log.debug("deleting Tbluserinrole instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see app.dao.IUserInRole#findById(java.lang.Integer)
	 */
	public Tbluserinrole findById(java.lang.Integer id) {
		log.debug("getting Tbluserinrole instance with id: " + id);
		try {
			Tbluserinrole instance = (Tbluserinrole) getHibernateTemplate()
					.get("app.model.Tbluserinrole", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see app.dao.IUserInRole#findByExample(app.model.Tbluserinrole)
	 */
	public List findByExample(Tbluserinrole instance) {
		log.debug("finding Tbluserinrole instance by example");
		try {
			List results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see app.dao.IUserInRole#findByProperty(java.lang.String, java.lang.Object)
	 */
	public List findByProperty(String propertyName, Object value) {
		log.debug("finding Tbluserinrole instance with property: "
				+ propertyName + ", value: " + value);
		try {
			String queryString = "from Tbluserinrole as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see app.dao.IUserInRole#findByRoleid(java.lang.Object)
	 */
	public List findByRoleid(Object roleid) {
		return findByProperty(ROLEID, roleid);
	}

	/* (non-Javadoc)
	 * @see app.dao.IUserInRole#findByUserid(java.lang.Object)
	 */
	public List findByUserid(Object userid) {
		return findByProperty(USERID, userid);
	}

	/* (non-Javadoc)
	 * @see app.dao.IUserInRole#findAll()
	 */
	public List findAll() {
		log.debug("finding all Tbluserinrole instances");
		try {
			String queryString = "from Tbluserinrole";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see app.dao.IUserInRole#merge(app.model.Tbluserinrole)
	 */
	public Tbluserinrole merge(Tbluserinrole detachedInstance) {
		log.debug("merging Tbluserinrole instance");
		try {
			Tbluserinrole result = (Tbluserinrole) getHibernateTemplate()
					.merge(detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see app.dao.IUserInRole#attachDirty(app.model.Tbluserinrole)
	 */
	public void attachDirty(Tbluserinrole instance) {
		log.debug("attaching dirty Tbluserinrole instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see app.dao.IUserInRole#attachClean(app.model.Tbluserinrole)
	 */
	public void attachClean(Tbluserinrole instance) {
		log.debug("attaching clean Tbluserinrole instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static IUserInRole getFromApplicationContext(
			ApplicationContext ctx) {
		return (IUserInRole) ctx.getBean("TbluserinroleDAO");
	}
}